package net.adetech.crj.dao;

import net.adetech.crj.entity.Schedule;
import net.adetech.crj.entity.ScheduleAmount;
import net.adetech.crj.entity.ScheduleTemplate;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ScheduleMapper {
    @Select("select * from crj_schedule where hall_id = #{hallId}")
    List<Schedule> getScheduleListByHallId(Long hallId);


    @Select("select * from crj_schedule_template where hall_id = #{hallId}")
    List<ScheduleTemplate> getScheduleTemplateListByHallId(Long hallId);

    @Select("select DAY_ID||'_'||TIME_PERIOD time_period,count(1) amount from CRJ_APPOINTMENT where STATE = '1' and hall_id = #{hallId} and service_type = #{serviceType} group by DAY_ID,TIME_PERIOD")
    List<ScheduleAmount> getScheduleAmountListByHallId(@Param("hallId") Long hallId,@Param("serviceType") String serviceType);


    @Select("select DAY_ID||'_'||TIME_PERIOD time_period,sum(case SERVICE_TYPE when 'M' then ID_NUMBER else '1' end ) amount from CRJ_APPOINTMENT where STATE = '1' and hall_id = #{hallId} and (service_type = 'M' or SERVICE_TYPE = 'B') group by DAY_ID,TIME_PERIOD")
    List<ScheduleAmount> getGroupAmountListByHallId(@Param("hallId") Long hallId);
}
